/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.ac.cput.garethc.chpt2.charsort.impl;

import za.ac.cput.garethc.chpt2.charsort.CharSort;


/**
 *
 * @author Gareth
 */
public class CharSortImpl implements CharSort
{

    @Override
    public char[] bubbleSort(char [] chars) 
    {
        boolean sorted = false;
        
        for (int i = 1; i <= chars.length && !sorted; i++)
        {
            sorted = true;
            for (int j = 0; j < chars.length - i; j++)
            {
                if (chars[j] > chars[j+1])
                {
                    sorted = false;
                    char tmp = chars[j];
                    chars[j] = chars[j+1];
                    chars[j+1] = tmp;
                }
            }
        }
        
        return chars;
    }
    
}
